package org.jeecg.modules.engineering.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.engineering.service.IEquipDataApiService;
import org.jeecg.modules.engineering.service.IEquipTelpoFaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@Api(tags="设备外部Api接口")
@RestController
//@RequestMapping("/b/api/equip")
@RequestMapping("/api/equip")
public class EquipDataForeignApiController {

    @Autowired
    private IEquipDataApiService equipDataApiService;

    @Autowired
    private IEquipTelpoFaceService equipTelpoFaceService;

    /**
     * 接收推送的数据
     * @return
     */
    @RequestMapping(value = "/acceptEventData")
    public Result<String> acceptEventData(@RequestParam(name="equipCode") String equipCode,
                                          @RequestParam(name="itemCode") String itemCode,
                                          @RequestParam(name="value") String value,
                                          @RequestParam(name="collectTime") Long collectTime,
                                          @RequestParam(name="registerCode") String registerCode) {
        try {
            equipDataApiService.acceptEventData(equipCode,itemCode,value,collectTime,registerCode);
            return Result.ok("推送成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.error("系统异常");
        }
    }

    /**
     * 接收天波人脸识别推送的刷脸记录数据
     * @return
     */
    @RequestMapping(value = "/acceptFaceEventRecords")
    public JSONObject acceptFaceEventRecords(@RequestBody JSONObject jsonRecord) {
        JSONObject json = new JSONObject();
        try {
            Result<String> result = equipTelpoFaceService.acceptFaceEventRecords(jsonRecord);
            if(result.isSuccess()){
                json.put("errCode","00");
            }else{
                json.put("errCode","01");
            }
        }catch (Exception e){
            e.printStackTrace();
            json.put("errCode","01");
        }
        return json;
    }
}
